package com.ct.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.ct.entity.enums.PageSize;
import com.ct.entity.po.Schedule;
import com.ct.entity.query.ScheduleQuery;
import com.ct.entity.query.SimplePage;
import com.ct.entity.vo.PaginationResultVO;
import com.ct.mappers.ScheduleMapper;
import com.ct.service.ScheduleService;
import com.ct.utils.StringTools;

import jakarta.annotation.Resource;

/**
 * 行程表 业务接口实现
 */
@Service("scheduleService")
public class ScheduleServiceImpl implements ScheduleService {

    @Resource
    private ScheduleMapper<Schedule, ScheduleQuery> scheduleMapper;

    /**
     * 根据条件查询列表
     */
    @Override
    public List<Schedule> findListByParam(ScheduleQuery param) {
        return this.scheduleMapper.selectList(param);
    }

    /**
     * 根据条件查询列表
     */
    @Override
    public Integer findCountByParam(ScheduleQuery param) {
        return this.scheduleMapper.selectCount(param);
    }

    /**
     * 分页查询方法
     */
    @Override
    public PaginationResultVO<Schedule> findListByPage(ScheduleQuery param) {
        int count = this.findCountByParam(param);
        int pageSize = param.getPageSize() == null ? PageSize.SIZE15.getSize() : param.getPageSize();

        SimplePage page = new SimplePage(param.getPageNo(), count, pageSize);
        param.setSimplePage(page);
        List<Schedule> list = this.findListByParam(param);
        PaginationResultVO<Schedule> result = new PaginationResultVO(count, page.getPageSize(), page.getPageNo(),
                page.getPageTotal(), list);
        return result;
    }

    /**
     * 新增
     */
    @Override
    public Integer add(Schedule bean) {
        return this.scheduleMapper.insert(bean);
    }

    /**
     * 批量新增
     */
    @Override
    public Integer addBatch(List<Schedule> listBean) {
        if (listBean == null || listBean.isEmpty()) {
            return 0;
        }
        return this.scheduleMapper.insertBatch(listBean);
    }

    /**
     * 批量新增或者修改
     */
    @Override
    public Integer addOrUpdateBatch(List<Schedule> listBean) {
        if (listBean == null || listBean.isEmpty()) {
            return 0;
        }
        return this.scheduleMapper.insertOrUpdateBatch(listBean);
    }

    /**
     * 多条件更新
     */
    @Override
    public Integer updateByParam(Schedule bean, ScheduleQuery param) {
        StringTools.checkParam(param);
        return this.scheduleMapper.updateByParam(bean, param);
    }

    /**
     * 多条件删除
     */
    @Override
    public Integer deleteByParam(ScheduleQuery param) {
        StringTools.checkParam(param);
        return this.scheduleMapper.deleteByParam(param);
    }

    /**
     * 根据ScheduleId获取对象
     */
    @Override
    public Schedule getScheduleByScheduleId(Integer scheduleId) {
        return this.scheduleMapper.selectByScheduleId(scheduleId);
    }

    /**
     * 根据ScheduleId修改
     */
    @Override
    public Integer updateScheduleByScheduleId(Schedule bean, Integer scheduleId) {
        return this.scheduleMapper.updateByScheduleId(bean, scheduleId);
    }

    /**
     * 根据ScheduleId删除
     */
    @Override
    public Integer deleteScheduleByScheduleId(Integer scheduleId) {
        return this.scheduleMapper.deleteByScheduleId(scheduleId);
    }

    @Override
    public List<Schedule> getAllScheduleListByTravelId(Integer travelId) {
        ScheduleQuery scheduleQuery = new ScheduleQuery();
        scheduleQuery.setTravelId(travelId);
        return this.scheduleMapper.selectList(scheduleQuery);
    }
}